﻿using NW_WEB_Service.App.Interface;
using NW_WEB_Service.com.app.services;
using Service.src.NW.Model.Drive;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Service.src.Flow.Server
{
    public class SysDriverAdressService : DBService, SysDriverAdressInterface
    {
        public SysPlcDriverAddress AddAddress(SysPlcDriverAddress address)
        {
            address = DBInstance.Install<SysPlcDriverAddress>(address);
            return address;
        }

        public bool DeleteAddress(int id)
        {
            return DBInstance.Delete(new SysPlcDriverAddress() { Id = id });
        }

        public bool DeleteAddressByDriverId(int DriverId)
        {
            return DBInstance.Delete<SysPlcDriverAddress>(d => d.DriverId == DriverId);
        }

        internal SysPlcDriverAddress GetAddressInfoById(int DBIndex, int Id)
        {
            SysPlcDriverAddress Info = DBInstance.Query<SysPlcDriverAddress>(i => i.Id == Id).FirstOrDefault();
            if (Info == null)
            {
                throw new Exception("获取地址异常，找不此地址");
            }
            return Info;
        }


        internal List<SysPlcDriverAddress> GetAllAddresslist(int DBIndex)
        {
            List<SysPlcDriverAddress> list = DBInstance.QueryAll<SysPlcDriverAddress>();
            return list;
        }

        public int UpldateAddress(SysPlcDriverAddress address)
        {
            int i = DBInstance.Update(address);
            return i;
        }
    }
}
